package com.gitee.enums;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.gitee.exception.OrderException;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Objects;
import java.util.stream.Stream;

@Getter
@AllArgsConstructor
public enum OrderTypeEnum {

    TANG_SHI(1, "堂食"),
    WAI_DAI(2, "外带")
    ;

    @EnumValue
    Integer code;

    String desc;

    public static OrderTypeEnum of(Integer code) {

        Objects.requireNonNull(code);

        return Stream.of(values())
                    .filter(bean -> bean.code.equals(code))
                    .findAny()
                    .orElseThrow(() -> new OrderException(ResponseEnum.PARAM_ERROR));
    }

}
